<template>
  <div class="sign">
    <!--标题-->
    <div class="logo">
      <img src="~/assets/img/logo.png"
           alt="logo">
    </div>
    <!--表单-->
    <div class="main">
      <div class="title">
        <a href="/login"
           class="active">登录</a>
        <span>·</span>
        <a href="/register">注册</a>
      </div>

      <div class="sign-up-container">
        <el-form ref="userForm"
                 :model="user">
          <el-form-item class="input-prepend restyle no-radius"
                        prop="mobile"
                        :rules="[{ required: true, message: '请输入手机号码', trigger: 'blur' },{validator: checkPhone, trigger: 'blur'}]">
            <el-input v-model="user.mobile"
                      type="text"
                      placeholder="手机号" />
            <i class="iconfont icon-phone" />
          </el-form-item>
          <el-form-item class="input-prepend"
                        prop="password"
                        :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
            <div>
              <el-input v-model="user.password"
                        type="password"
                        placeholder="设置密码" />
              <i class="iconfont icon-password" />
            </div>
          </el-form-item>

          <div class="btn">
            <input type="button"
                   class="sign-up-button"
                   value="登录"
                   @click="submitLogin()">
          </div>
        </el-form>
        <div class="more-sign">
          <h6>社交帐号登录</h6>
          <ul>
            <li><a id="weixin"
                 class="weixin"
                 target="_blank"
                 href="http://10.18.19.18:8160/api/ucenter/wx/login">
                <i class="iconfont icon-weixin" /></a></li>
            <li><a id="qq"
                 class="qq"
                 target="_blank"
                 href="#"><i class="iconfont icon-qq" /></a></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import '~/assets/css/sign.css'
import '~/assets/css/iconfont.css'

import loginApi from '@/utils/api/login'

export default {
  data() {
    return {
      user: {
        mobile: '',
        password: ''
      },
      loginInfo: {}
    }
  },
  methods: {
    submitLogin() {
      loginApi.submitLogin(this.user).then(res => {
        if (res.data.success) {
          // cookie.set('guli_token', res.data.data.token, { domain: 'localhost' })
          this.$cookies.set('guli_token', res.data.data.token, { domain: 'localhost' })
          localStorage.setItem('guli_token', res.data.data.token)
          window.location.href = '/'
        }
      })
    },
    checkPhone(rule, value, callback) {
      if (!(/^1[34578]\d{9}$/.test(value))) {
        return callback(new Error('手机号码格式不正确'))
      }
      return callback()
    }
  }
}
</script>

<style>
</style>